package nuc.soft.A01.jzs.services.problem;

import java.util.ArrayList;

import nuc.soft.A01.jzs.dao.problem.SubBlankMapper;
import nuc.soft.A01.jzs.model.problem.SubBlankProblem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tool.Tools;


@Service
public class SubBlankService {

	@Autowired
	private SubBlankMapper dao;
	
	public int insert(SubBlankProblem problem)
	{
		problem.setId(Tools.getUUID());
		return dao.insert(problem);
	}
	
	public int update(SubBlankProblem problem)
	{
		return dao.update(problem);
	}
	
	public int delete(SubBlankProblem problem)
	{
		return dao.delete(problem);
	}
	
	public int deleteById(String id)
	{
		return dao.deleteById(id);
	}
	
	public int deleteById(SubBlankProblem problem)
	{
		return dao.deleteById(problem.getId());
	}
	
	public ArrayList<SubBlankProblem>	getAllSubBlank()
	{
		return (ArrayList<SubBlankProblem>) dao.getAllObject();
	}
	
	public  ArrayList<SubBlankProblem> getSearchPrblem(String searchname)
	{
		 ArrayList<SubBlankProblem> allproblem=this.getAllSubBlank();
		 ArrayList<SubBlankProblem> searchproblem=new ArrayList<SubBlankProblem>();
		 for(SubBlankProblem problem:allproblem)
		 {
			 if(problem.getQuestion().contains(searchname))
			 {
				 searchproblem.add(problem);
			 }
		 }
		 return searchproblem;
	}
	
	public SubBlankProblem getASubBlankById(String id)
	{
		return (SubBlankProblem) dao.getAObjectById(id);
	}
}
